/**************************************************************************
*   Copyright (C) 2010 Chernov Dmitry                                     *
*                                                                         *
*   This program is free software; you can redistribute it and/or modify  *
*   it under the terms of the GNU General Public License as published by  *
*   the Free Software Foundation; either version 2 of the License, or     *
*   (at your option) any later version.                                   *
*                                                                         *
*   This program is distributed in the hope that it will be useful,       *
*   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
*   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
*   GNU General Public License for more details.                          *
*                                                                         *
*   You should have received a copy of the GNU General Public License     *
*   along with this program; if not, write to the                         *
*   Free Software Foundation, Inc.,                                       *
*   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
***************************************************************************/

#ifndef MARBLE_H
#define MARBLE_H

#include <vector>


class Marble
{
public:
    Marble( int id, int pos ) : m_id(id),
                                m_positioned(false)
    {
        m_positions.push_back(pos);
    }

    int getPosition() const
    {
        return m_positions.back();
    }

    int getId() const
    {
        return m_id;
    }

    int lastMoved() const
    {
        if( m_whenMoved.size() > 0 )
            return m_whenMoved.back();

        return -1;
    }

    void move( int pos, int turn )
    {
        m_positions.push_back(pos);
        m_whenMoved.push_back(turn);
    }

    void setPositioned( int turn )
    {
        m_positioned = true;
    }

    bool positioned() const
    {
        return m_positioned;
    }

    void unmove( int turn )
    {
        if( lastMoved() == turn )
        {
            if( m_positions.size() > 1 )
            {
                m_positions.pop_back();
                m_whenMoved.pop_back();
            }

            if( m_positioned )
                m_positioned = false;
        }
    }

private:
    std::vector<int> m_positions;
    std::vector<int> m_whenMoved;
    int m_id;
    bool m_positioned;
};

class Hole
{
public:
    const int m_position;
    const int m_id;

    Hole( int id, int pos ) : m_position(pos), m_id(id)//, m_filled(false)
    {}

    bool matches( int marble_id ) const
    {
        return m_id == marble_id;
    }
};

class Wall
{
public:
    enum wallType
    {
        wall_top = 1,
        wall_right = 2,
        wall_bottom = 4,
        wall_left = 8,
    };

    const int m_position;

    Wall( int pos, wallType wt ) : m_position(pos), m_type(wt)
    {}

    void addWall( wallType wt )
    {
        m_type |= wt;
    }

    bool is( wallType wt ) const
    {
        return ( ( m_type & wt ) == wt );
    }

private:
    int m_type;
};

#endif // MARBLE_H
